<?php

namespace App\Backend\Controllers;

use App\Backend\Controllers\BaseController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;

use App\Backend\Service\DoubanpostService;

/**
 * 豆瓣
 */
class DoubanpostController extends BaseController
{
    private $getRules=[
            'img_url'=> 'required',
            'type'=> 'required',
            'sort'=> 'required',
            'status'=> 'required',
    ];
    private $getRulesMessage=[
            'img_url.required'=> '图片地址不能为空',
            'type.required'=> 'banner类型不能为空',
            'sort.required'=> '排序不能为空',
            'status.required'=> '状态不能为空',
    ];
    
    public function __construct(DoubanpostService $centerService)
    {
        $this->repository = $centerService;
        parent::__construct();
    }


    /**
     * 列表
     */
    public function getList(Request $request)
    {
        //dd($request);
        $data=[
            'title'=>$request->input("title"),
            'start_date'=>$request->input("start_date"),
            'end_date'=>$request->input("end_date"),
            'check_status'=>$request->input("check_status"),
            'check_result'=>$request->input("check_result"),
            'channel'=>$request->input("channel"),
        ];
        $this->success($this->repository->getList($request,$data));
    }

    

    /**
     * 添加
     */
    public function add(Request $request)
    {
        $data = [
            'img_url'=>$request->input('img_url'),
            'type'=>$request->input('type'),
            'sort'=>$request->input('sort'),
            'status'=>$request->input('status'),
            'start_date'=>$request->input('start_date'),
            'end_date'=>$request->input('end_date'),
            'takt_time'=>$request->input('takt_time'),
            'title'=>$request->input('title'),
            'category'=>$request->input('category'),
            'intro'=>$request->input('intro'),
            'create_time'=>time(),
            'update_time'=>time(),
        ];
        $this->checkrule($data, $this->getRules, $this->getRulesMessage);
        
        $this->repository->add($request,$data);
        
    }   


     /**
     * 编辑
     */
    public function edit(Request $request)
    {
        $data=[
            'unique_id'=>$request->input("unique_id"),
            'check_result'=>$request->input("check_result"),
            'check_content'=>$request->input("check_content"),
        ];
        $unique_id =$request->input("unique_id");
        if(empty($unique_id)){
            $this->error('参数错误');
        }
     
        $this->repository->edit($request,$data,$unique_id);
    }

    // 详情
     public function detail(Request $request)
    {
        $unique_id = $request->input('unique_id');
        if(empty($unique_id)){
            $this->error('参数错误');
        }
        $this->success($this->repository->detail($request,$unique_id));
    }

    /**
     * 删除
     */
    public function del(Request $request)
    {
        $ids = $request->input('unique_id');
        if(empty($ids)){
            $this->error('参数错误');
        }
        $this->repository->del($ids);
    }



}
